//
//  LTShareButton.m
//  LTChat
//
//  Created by 张豪 on 2017/8/8.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import "LTShareButton.h"


@interface LTShareButton()

@property (nonatomic, strong) UILabel* titleLab;

@end

@implementation LTShareButton

- (void)setupWithIcon:(NSString* )icon withTitle:(NSString* )title pushUrl:(NSString* )ulrStr {
    [self.iconImageView sd_setImageWithURL:kStringIsEmpty(icon) ? nil : [NSURL URLWithString:icon] placeholderImage:[UIImage imageNamed:@"link_placeholder"]];
    self.iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.iconImageView.clipsToBounds = YES;
    self.titleLab.text = title;
    self.ulrStr = ulrStr;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        
        [self setBackgroundImage:[UIImage imageWithColor:RGB(244, 244, 246)] forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage imageWithColor:RGB(205, 211, 224)] forState:UIControlStateHighlighted];
        
        [self yd_addSubView];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self setBackgroundImage:[UIImage imageWithColor:RGB(244, 244, 246)] forState:UIControlStateNormal];
    [self setBackgroundImage:[UIImage imageWithColor:RGB(205, 211, 224)] forState:UIControlStateHighlighted];
    
    [self yd_addSubView];
}

#pragma mark - 添加视图方法
- (void)yd_addSubView {
    [self addSubview:self.iconImageView];
    [self addSubview:self.titleLab];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.centerY.equalTo(self);
        make.height.mas_equalTo(40);
        make.width.equalTo(self.iconImageView.mas_height).priority(900);
    }];
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.mas_right).offset(6).priority(900);
        make.centerY.equalTo(self);
        make.right.lessThanOrEqualTo(self.mas_right).offset(-8);
    }];
}

#pragma mark - 懒加载 iconImageView
- (UIImageView* )iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc]init];
    }
    
    return _iconImageView;
}

#pragma mark - 懒加载 titleLab
- (UILabel* )titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel cz_labelWithText:@"" fontSize:13 color:[UIColor blackColor]];
        _titleLab.numberOfLines = 2;
    }
    
    return _titleLab;
}

@end
